/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Draw;

import java.awt.AlphaComposite;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.geom.Line2D;
import java.util.List;
import javax.swing.JPanel;

/**
 *
 * @author Win 8 64Bit VS7
 */
public class MyPanel extends JPanel {

    private Point startPoint;
    private Point endPoint;
    private Graphics2D graph2D;

    
    public MyPanel() {
        this.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
//                startPoint = new Point(e.getX(), e.getY());
//                endPoint = startPoint;
//                repaint();
//                System.out.println("Pressed: " + e.getPoint().toString());
            }

            public void mouseReleased(MouseEvent e) {
//                startPoint = null;
//                endPoint = null;
//                repaint();
                System.out.println("Released: " + e.getPoint().toString());
            }
        });

        this.addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseDragged(MouseEvent e) {
//                endPoint = new Point(e.getX(), e.getY());
//                repaint();
                System.out.println("Dragged: " + e.getPoint().toString());
            }
        });
    }

    void drawBackground(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        g2.setPaint(Color.LIGHT_GRAY);
        for (int i = 0; i < getSize().width; i += 10) {
            Shape line = new Line2D.Float(i, 0, i, getSize().height);
            g2.draw(line);
        }
        for (int i = 0; i < getSize().height; i += 10) {
            Shape line = new Line2D.Float(0, i, getSize().width, i);
            g2.draw(line);
        }
    }

    void drawListShape(List<Shape> listShape) {
        Graphics2D g2 = (Graphics2D) this.getGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Color[] colors = {Color.YELLOW, Color.MAGENTA, Color.CYAN, Color.RED, Color.BLUE, Color.PINK};
        int colorIndex = 0;

        g2.setStroke(new BasicStroke(2));
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.50f));

        for (Shape s : listShape) {
            g2.setPaint(Color.BLACK);
            g2.draw(s);
            g2.setPaint(colors[(colorIndex++) % 6]);
            g2.fill(s);
        }

    }

    @Override
    public void paint(Graphics g) {
        graph2D = (Graphics2D) g;
        
    }
}
